﻿//Creating a button with image style
//text: text's button
//link: link's button
//onclick: determine whether there is an event onclick or not
function getTextFCK(FCKname)
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(FCKname) ;
		// Get the editor contents in XHTML.
	return oEditor.GetXHTML(true);// "true" means you want it formatted.
}
function InsertTextFCK(FCKname, sContent)
{
    var oEditor = FCKeditorAPI.GetInstance(FCKname) ;
    oEditor.SetHTML(sContent);
}

function doView(url){
    window.location.href = url;
    return false;
}    
    
function displayButton(text,link,onclick)
{    
    var btn = "<table cellpadding='0' cellspacing='0'><tr>"
    + "<td class='Button_Background_Left'></td>"
    if(onclick !='' || onclick!=null)
        btn += "<td class='Button_Background_Center'><a href='"+ link + "' class=LinkButton onclick=\"" + onclick + "\">" + text + "</a></td>";
    else
        btn += "<td class='Button_Background_Center'><a href='"+ link + "' class=LinkButton>" + text + "</a></td>";    
    btn += "<td class='Button_Background_Right'></td></tr></table>"; 
    document.write(btn);
}
var relatePath = '';
function openSelectWindow(valueId, textId){
    var strFeatures = '';
    if(document.all){
        strFeatures = 'dialogWidth:290px;dialogHeight:320px;dialogTop:200px;dialogLeft:200px;titlebar:1;resizable:0;status:0;scrollbars:0';
        window.showModalDialog(relatePath+'CompDenu/SelectPersonFrm.aspx?valueId='+valueId+'&textId='+textId+'&cache=' + new Date().getTime(),window,strFeatures);
    }else{
        strFeatures = 'width=290px,height=300px,top=200px,left=200px,titlebar=1,menubar=0,toolbar=0,resizable=0,status=1,scrollbars=0,dependent=yes';
        window.open(relatePath+'CompDenu/SelectPersonFrm.aspx?valueId='+valueId+'&textId='+textId,'_blank',strFeatures);
    }    
} 
function openSelectDiaBanWindow(objId,hidId){
    var strFeatures = '';
    if(document.all){
        strFeatures = 'dialogWidth:250px;dialogHeight:300px;dialogTop:200px;dialogLeft:200px;titlebar:1;resizable:0;status:0;scrollbars:0';
        window.showModalDialog(relatePath+'CompDenu/SelectDiaBan.aspx?objId='+objId+'&hidId='+hidId+'&cache=' + new Date().getTime(),window,strFeatures);
    }else{
        strFeatures = 'width=250px,height=300px,top=200px,left=200px,titlebar=1,menubar=0,toolbar=0,resizable=0,status=1,scrollbars=0,dependent=yes';
        window.open(relatePath+'CompDenu/SelectDiaBan.aspx?objId='+objId+'&hidId='+hidId,'_blank',strFeatures);
    }    
} 
function openSelectPersonsWindow(objId,hidId){
    var strFeatures = '';
    if(document.all){
        strFeatures = 'dialogWidth:600px;dialogHeight:320px;dialogTop:200px;dialogLeft:200px;titlebar:1;resizable:0;status:0;scrollbars:0';
        window.showModalDialog(relatePath+'CompDenu/SelectVanBan.aspx?objId='+objId+'&hidId='+hidId+'&cache=' + new Date().getTime(),window,strFeatures);
    }else{
        strFeatures = 'width=620px,height=300px,top=200px,left=200px,titlebar=1,menubar=0,toolbar=0,resizable=0,status=1,scrollbars=0,dependent=yes';
        window.open(relatePath+'CompDenu/SelectVanBan.aspx?objId='+objId+'&hidId='+hidId,'_blank',strFeatures);
    }    
} 
function openSelectOrgansWindow(objId,hidId,IsDenDi){
    var strFeatures = '';
    if(document.all){
        strFeatures = 'dialogWidth:600px;dialogHeight:370px;dialogTop:200px;dialogLeft:200px;titlebar:1;resizable:0;status:0;scrollbars:0';
        window.showModalDialog(relatePath+'CompDenu/SelectOrgans.aspx?objId='+objId+'&hidId='+hidId+ '&IsDenDi=' + IsDenDi +'&cache=' + new Date().getTime(),window,strFeatures);
    }else{
        strFeatures = 'width=620px,height=370px,top=200px,left=200px,titlebar=1,menubar=0,toolbar=0,resizable=0,status=1,scrollbars=0,dependent=yes';
        window.open(relatePath+'CompDenu/SelectOrgans.aspx?objId='+objId+'&hidId='+hidId+ '&IsDenDi=' + IsDenDi,'_blank',strFeatures);
    }    
}

function openSelectOrganUniqueWindow(objId, hidId, txtCapCQId, hidCapCQId, IsDenDi){
    var strFeatures = '';
    if(IsDenDi==null) IsDenDi = 0;
    if(document.all){
        strFeatures = 'dialogWidth:600px;dialogHeight:370px;dialogTop:200px;dialogLeft:200px;titlebar:1;resizable:0;status:0;scrollbars:0';
        window.showModalDialog(relatePath+'CompDenu/SelectOrganUnique.aspx?objId='+objId+'&hidId='+hidId+'&txtCapCQId='+txtCapCQId+'&hidCapCQId='+hidCapCQId + '&IsDenDi=' + IsDenDi + '&cache=' + new Date().getTime(),window,strFeatures);
    }else{
        strFeatures = 'width=620px,height=370px,top=200px,left=200px,titlebar=1,menubar=0,toolbar=0,resizable=0,status=1,scrollbars=0,dependent=yes';
        window.open(relatePath+'CompDenu/SelectOrganUnique.aspx?objId='+objId+'&hidId='+hidId+'&txtCapCQId='+txtCapCQId+'&hidCapCQId='+hidCapCQId+ '&IsDenDi=' + IsDenDi,'_blank',strFeatures);
    }    
}   
    
function openSelectDepartmentWindow(objId,hidId,personObjId,personHidId){
    var strFeatures = '';
    if(document.all){
        strFeatures = 'dialogWidth:290px;dialogHeight:320px;dialogTop:200px;dialogLeft:200px;titlebar:1;resizable:0;status:0;scrollbars:0';
        window.showModalDialog(relatePath+'CompDenu/SelectDepartment.aspx?objId='+objId+'&hidId='+hidId + '&personObjId='+personObjId+'&personHidId='+personHidId+'&cache=' + new Date().getTime(),window,strFeatures);
    }else{
        strFeatures = 'width=290px,height=300px,top=200px,left=200px,titlebar=1,menubar=0,toolbar=0,resizable=0,status=1,scrollbars=0,dependent=yes';
        window.open(relatePath+'CompDenu/SelectDepartment.aspx?objId='+objId+'&hidId='+hidId + '&personObjId='+personObjId+'&personHidId='+personHidId,'_blank',strFeatures);
    }    
} 
function openSelectLeaderWindow(objId,hidId,cvObjId){
    var strFeatures = '';
    var strVar = '';
    if(cvObjId!=null&&cvObjId!='') strVar = '&cvObjId=' + cvObjId;
    if(document.all){
        strFeatures = 'dialogWidth:290px;dialogHeight:320px;dialogTop:200px;dialogLeft:200px;titlebar:1;resizable:0;status:0;scrollbars:0';
        window.showModalDialog(relatePath+'CompDenu/SelectLeader.aspx?objId='+objId+'&hidId='+hidId + strVar+'&cache=' + new Date().getTime(),window,strFeatures);
    }else{
        strFeatures = 'width=290px,height=300px,top=200px,left=200px,titlebar=1,menubar=0,toolbar=0,resizable=0,status=1,scrollbars=0,dependent=yes';
        window.open(relatePath+'CompDenu/SelectLeader.aspx?objId='+objId+'&hidId='+hidId + strVar,'_blank',strFeatures);
    }    
}  
function openSelectDocumentsWindow(hidId, pbId, urlBase){
    var strFeatures = '';
    width = screen.width - 100;
    height = screen.height -100;
    if(width > 1004) width = 1004;
    var strVar = '';
    if(pbId!=null&&pbId!='') strVar = '&pbId=' + pbId;
    if(document.all){
        strFeatures = 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;dialogTop:50px;dialogLeft:50px;titlebar:1;resizable:0;status:0;scrollbars:0';
        window.showModalDialog(relatePath+'CompDenu/SelectDocuments.aspx?hidId='+hidId + strVar +'&urlBase='+ urlBase +'&cache=' + new Date().getTime(),window,strFeatures);
    }else{
        strFeatures = 'width=' + width + 'px,height=' + height + 'px,top=50px,left=50px,titlebar=1,menubar=0,toolbar=0,resizable=0,status=1,scrollbars=0,dependent=yes';
        window.open(relatePath+'CompDenu/SelectDocuments.aspx?hidId='+hidId + strVar +'&urlBase='+ urlBase ,'_blank',strFeatures);
    }    
} 

function openSelectDepartmentsWindow(objId,hidId){
    var strFeatures = '';
    if(document.all){
        strFeatures = 'dialogWidth:600px;dialogHeight:220px;dialogTop:200px;dialogLeft:200px;titlebar:1;resizable:0;status:0;scrollbars:0';
        window.showModalDialog(relatePath+'IncomingDocument/SelectDepartments.aspx?objId='+objId+'&hidId='+hidId+'&cache=' + new Date().getTime(),window,strFeatures);
    }else{
        strFeatures = 'width=620px,height=200px,top=200px,left=200px,titlebar=1,menubar=0,toolbar=0,resizable=0,status=1,scrollbars=0,dependent=yes';
        window.open(relatePath+'CompDenu/SelectDepartments.aspx?objId='+objId+'&hidId='+hidId,'_blank',strFeatures);
    }    
} 
 
function openSelectOutDocumentsWindow(hidId, pbId, urlBase){
    var strFeatures = '';
    width = screen.width - 100;
    height = screen.height -100;
    if(width > 1004) width = 1004;
    var strVar = '';
    if(pbId!=null&&pbId!='') strVar = '&pbId=' + pbId;
    if(document.all){
        strFeatures = 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;dialogTop:50px;dialogLeft:50px;titlebar:1;resizable:0;status:0;scrollbars:0';
        window.showModalDialog(relatePath+'CompDenu/SelectOutDocuments.aspx?hidId='+hidId + strVar +'&urlBase=' + urlBase +'&cache=' + new Date().getTime(),window,strFeatures);
    }else{
        strFeatures = 'width=' + width + 'px,height=' + height + 'px,top=50px,left=50px,titlebar=1,menubar=0,toolbar=0,resizable=0,status=1,scrollbars=0,dependent=yes';
        window.open(relatePath+'CompDenu/SelectOutDocuments.aspx?hidId='+hidId + strVar+'&urlBase=' + urlBase  ,'_blank',strFeatures);
    }    
}  

function openSelectTemplateWindow(){
    var strFeatures = '';
    strFeatures = 'width=450px,height=420px,top=200px,left=200px,titlebar=1,menubar=0,toolbar=0,resizable=1,status=1,scrollbars=0,dependent=yes';
    window.open(relatePath+'CompDenu/SelectDocumentTemplate.aspx','_blank',strFeatures);
} 
/*---------------------------*/
function isEmail(email) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email))	
		return false;
	else
		return true;
}

function isValidURL(urlStr) {
	if (urlStr == "" || urlStr == null)
		return false;
	urlStr = urlStr.replace(" ","");
	//if (urlStr.indexOf(" ")!=-1)	
		//return false;
	urlStr=urlStr.toLowerCase();
	var urlPat=/^http:\/\/([\-\+a-z0-9]*)\.(\w*)/;
	var matchArray=urlStr.match(urlPat);
	if (matchArray==null)
		return false;
	return true;
}

function isNummeric(text){
	var re = /^[0-9]{1,4}$/;	
	return re.test(text);
}

function EnsureNumericKeyEntry(x){
	var kCode , kChar
	kCode = event.keyCode
	kChar = String.fromCharCode(kCode)
	
	if(kCode == 32){
		return false;
	}

	if(!isNaN(kChar)){
		return true;
	}else{
		if(kChar == "."){
			var index
			index = x.indexOf(".")
			if(index!=-1){
				return false
			}
		}else{
			if(kCode!=8){
				return false
			}
		}
		return true;
	}
}
//So sanh 2 ngay 
function CompDate(strDate1,strDate2){
    var m1, d1, y1;
    var m2, d2, y2;
    var s, pos1, pos2;
    var s = strDate1, s1 = strDate2;
    if (s.length == 0 || s1.length == 0) return true;

    pos1    = s.indexOf("/", 0);
    pos2    = s.indexOf("/", pos1+1);
    d1      = parseInt(s.substr(0, pos1), 10);
    m1      = parseInt(s.substr(pos1+1, pos2-pos1-1), 10);
    y1      = parseInt(s.substr(pos2+1, s.length-pos2), 10);

    pos1    = s1.indexOf("/", 0);
    pos2    = s1.indexOf("/", pos1+1);
    d2      = parseInt(s1.substr(0, pos1), 10);
    m2      = parseInt(s1.substr(pos1+1, pos2-pos1-1), 10);
    y2      = parseInt(s1.substr(pos2+1, s1.length-pos2), 10);

    var d1  = new Date(y1, m1, d1);
    var d2  = new Date(y2, m2, d2);
    if (d1 > d2) 
        return true;
    else
        return false;
}

 function checkDate(valueDate) {
	ok = true;
  	if (valueDate.toString().length > 0)
	{
		if (isNaN(Date.parse(valueDate))) 
		{
			ok = false;
		}
		else {
			pos = valueDate.toString().lastIndexOf("/");			
			year = valueDate.toString().substr(pos + 1);
			
			if (year.toString().length != 4) {
				ok = false;
			}
			else {
				if (isNaN(year.toString())) {
					ok = false;
				}
			}
		}		
	}	
	
	return ok;
}


function trim(s){
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')){
    s = s.substring(1,s.length);
  }
  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')){
    s = s.substring(0,s.length-1);
  }
  return s;
}

// filter the files before Uploading for text file only  
   function CheckForTestFile(objID) 
   {
        var file = document.getElementById(objID);
        var fileName=file.value;    
        
        //Checking for file browsed or not 
        if (util.Trim(fileName) =='' )
        {
//            alert("Please select a file to upload!!!");
//            file.focus();
//            return false;
            return true;
        }     
 
       //Setting the extension array for diff. type of text files 
       var extArray = new Array(".txt", ".doc", ".rtf", ".docx", ".pdf", ".rar", ".zip");       
 
       //getting the file name
       while (fileName.indexOf("\\") != -1)
         fileName = fileName.slice(fileName.indexOf("\\") + 1);
 
       //Getting the file extension                     
       var ext = fileName.slice(fileName.lastIndexOf(".")).toLowerCase();      
 
       //matching extension with our given extensions.
       for (var i = 0; i < extArray.length; i++) 
       {
         if (extArray[i] == ext) 
         { 
           return true;
         }
       }  
       if (util.Trim(fileName) != '')
       {
             alert("Xin vui lòng chọn file có kiểu:  " 
               + (extArray.join("  ")));
               file.focus();
            return false;               
       } 
   } 
   
   // Format and round a float with the number of digits after the point
   // Value: the number need format, precision: the number of digits after the point
   // Example: toFixed(2.73742, 2) = 2.74
   function toFixed(value, precision) {
        var pow = Math.pow(10, precision || 0);
        return String(Math.round(value*pow)/pow);
   }